package com.koron.common.core.config;

import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class CasUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        CasUser attr = parameter.getParameterAnnotation(CasUser.class);
        return parameter.getParameterType().equals(EamUser.class) && attr != null;
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
        //从redis拿到用户信息，然后注入方法参数
        return ThreadLocalContext.get();
    }

}
